// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   DataInfo.java

package include.nseer_db;

import java.io.PrintStream;
import java.sql.*;
import java.util.Vector;

// Referenced classes of package include.nseer_db:
//			nseer_db

public class DataInfo
{

	private nseer_db db;
	private boolean init;
	String database;

	public DataInfo(String database)
	{
		db = null;
		init = false;
		this.database = null;
		setDatabase(database);
		init();
	}

	public DataInfo()
	{
		db = null;
		init = false;
		database = null;
	}

	public void setDatabase(String database)
	{
		this.database = database;
	}

	private void init()
	{
		if (!init)
		{
			db = new nseer_db(database);
			init = true;
		}
	}

	private ResultSetMetaData getResultSetMetaDate(String table)
	{
		ResultSetMetaData rsmd;
		ResultSet rs = db.executeQuery((new StringBuilder("select * from ")).append(table).toString());
		if (!rs.next())
			break MISSING_BLOCK_LABEL_49;
		rsmd = rs.getMetaData();
		return rsmd;
		SQLException e;
		e;
		e.printStackTrace();
		return null;
		return null;
	}

	public int getNumberOfColumns(String table)
	{
		ResultSetMetaData rsmd = getResultSetMetaDate(table);
		int result = 0;
		if (rsmd == null)
			return 0;
		try
		{
			result = rsmd.getColumnCount();
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		return result;
	}

	public String[] getColumnNames(String table)
	{
		ResultSetMetaData rsmd = getResultSetMetaDate(table);
		String result[];
		int numberOfColumns = rsmd.getColumnCount();
		result = new String[numberOfColumns];
		for (int i = 1; i <= numberOfColumns; i++)
			result[i - 1] = rsmd.getColumnName(i);

		return result;
		SQLException e;
		e;
		e.printStackTrace();
		return null;
	}

	public String getColumnType(String table, String column)
	{
		ResultSetMetaData rsmd = getResultSetMetaDate(table);
		int numberOfColumns;
		int i;
		numberOfColumns = rsmd.getColumnCount();
		i = 1;
		  goto _L1
_L3:
		if (rsmd.getColumnName(i).equals(column))
			return rsmd.getColumnTypeName(i);
		i++;
_L1:
		if (i <= numberOfColumns) goto _L3; else goto _L2
_L2:
		break MISSING_BLOCK_LABEL_64;
		SQLException e;
		e;
		e.printStackTrace();
		return "UNKOWN";
	}

	public String[] getNumericColumn(String table)
	{
		Vector vt = new Vector();
		String names[] = getColumnNames(table);
		for (int i = 0; i < names.length; i++)
		{
			String type = getColumnType(table, names[i]);
			if (type.equals("INT") || type.equals("LONG") || type.equals("TINY") || type.equals("FLOAT") || type.equals("DOUBLE"))
				vt.addElement(names[i]);
		}

		String result[] = new String[vt.size()];
		vt.toArray(result);
		return result;
	}

	public void finalize()
	{
		db.close();
	}

	public static void main(String args[])
	{
		DataInfo data = new DataInfo("rajdb");
		String names[] = data.getNumericColumn("product");
		for (int i = 0; i < names.length; i++)
			System.out.println((new StringBuilder("type:")).append(data.getColumnType("product", names[i])).toString());

	}
}
